package com.naiterui.ehp.bs.doctor.dao.mongo;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import com.naiterui.ehp.bs.doctor.prodocl.NoticeReader;

/**
 * 公告阅读数mongo
 *
 * @since 2.3.0
 */
@Repository
public class AdNoticeReaderDao extends MongoBaseDao {

    /**
     * 公告阅读数记录collectionName
     */
    private static final String COLLECTION_NAME = "m_notice_reader";

    @Autowired
    private MongoTemplate mongoTemplate;

    /**
     * 添加
     * NoticeReaderDao.saveNoticeReader()
     *
     * @param noticeReader
     *
     * @Date 2016年3月30日
     * @since 2.3.0
     */
    public void saveNoticeReader(NoticeReader noticeReader) {

        super.save(noticeReader, COLLECTION_NAME);
    }

    /**
     * 获取
     * NoticeReadDao.getNoticeReader()
     *
     * @param noticeId
     *
     * @return
     *
     * @Date 2016年6月28日
     * @since 2.5.0
     */
    public NoticeReader getNoticeReader(Long noticeId, Long reader) {

        Criteria criteria = Criteria.where("noticeId").is(noticeId).and("reader").is(reader);
        Query query = Query.query(criteria);
        List<NoticeReader> results = super.find(query, NoticeReader.class, COLLECTION_NAME);
        return results.size() > 0 ? results.get(0) : null;
    }

    @Override
    protected MongoTemplate getMongoTemplate() {
        return mongoTemplate;
    }

}
